package com.acme.bankapp;

import com.acme.bankapp.domain.Bank;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class BankServer {
    private Bank bank;

    public BankServer(Bank bank) {
        this.bank = bank;
    }

    public void newConnection (int socketNumber) {
        new Thread() {
            @Override
            public void run() {
                try (ServerSocket ss = new ServerSocket(socketNumber);
                     Socket s = ss.accept()) {
                    Connection connection = new Connection(s.getInputStream(), s.getOutputStream());
                    connection.start(bank);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }
}
